/**
 * 条件：医院与科室的二级联动，职位
 * @returns
 */
$(function () {
    console.log("页面加载完成事件");
    /*医院与科室*/
    $.ajax({
        url: "../../DropDownBoxQuery/findHospitalDempartment",
        type: "post",
        dataType: "json",
        success: function (map) {
            var hospitalList = map.hospitalList;
            var departmentList = map.departmentList;
            var hospital_select = document.getElementById("user_hospital");
            var department_select = document.getElementById("user_department");
            //加载
            hospital_select.innerHTML = "<option value=''>请选择医院</option>";
            for (var i = 0; i < hospitalList.length; i++) {
                var opt = document.createElement("option");
                opt.innerText = hospitalList[i].hospitalName;
                opt.setAttribute("value", hospitalList[i].hospitalId);
                hospital_select.appendChild(opt);
            }
            //给省份添加change事件，选择省份，获取城市
            hospital_select.onchange = function () {
                //获取ID
                var userHospitalCode = hospital_select.value;
                //先清除原来的城市数据
                department_select.innerHTML = "<option value=''>请选择科室</option>";
                //根据code获取
                for (var i = 0; i < departmentList.length; i++) {
                    if (departmentList[i].hospitalId == userHospitalCode) {
                        var opt = document.createElement("option");
                        opt.innerText = departmentList[i].departmentName;
                        opt.setAttribute("value", departmentList[i].departmentId);
                        department_select.appendChild(opt);
                    }
                }
            }
        },
        error: function () {
            console.log("数据返回失败");
        }
    });

    /*职位*/
    $.ajax({
        url: "../../DropDownBoxQuery/findRole",
        type: "post",
        dataType: "json",
        success: function (map) {
            var roleList = map.roleList;
            var role_select = document.getElementById("user_role");
            //消除下拉框
            //加载
            for (var i = 0; i < roleList.length; i++) {
                var opt = document.createElement("option");
                opt.innerText = roleList[i].roleName;
                opt.setAttribute("value", roleList[i].roleId);
                role_select.appendChild(opt);
            }
        },
        error: function () {
            console.log("数据返回失败");
        }
    });

})